from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor
from sklearn.linear_model import Ridge
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV

boston = load_boston()
X_train,X_test,y_train,y_test = train_test_split(boston.data,boston.target,random_state=2)

param_rf = {'n_estimators':[50,75,100,125],'max_depth':[3,4,5]}

grid_rf = GridSearchCV(RandomForestRegressor(),param_rf,cv=5)
grid_rf.fit(X_train,y_train)

print(grid_rf.best_params_)
print(grid_rf.best_score_)

param_lr ={'alpha':[0.01,0.1,1,10]}
grid_lr = GridSearchCV(Ridge(),param_lr,cv=5)
grid_lr.fit(X_train,y_train)
print(grid_lr.best_params_)
print(grid_lr.best_score_)

print(grid_rf.score(X_test,y_test))
print(grid_lr.score(X_test,y_test))